<?php
require_once "../include/connectionHandlers/sessionHandling.php";
require_once "../include/connectionHandlers/flickrHandling.php";

class menu_controller
{
	
	private $sesHandler = null;
	
	public function __construct()
	{
		$this->sesHandler = sessionHandling::instantiate();
		
		if(!($this->sesHandler->isAuthenticated()))
		{
			header("location:login.php");
		}
		if(isset($_POST["flickrConnect"]))
			{
				if(isset($_POST["flickr_email"]))
				{
					$connectionHandler = new filckrHandling();
					$sets = $connectionHandler->getSets($_POST["flickr_email"]);
					
					foreach($sets as $key=>$value)
					{
						$setName = $key;
						$photoArray = $connectionHandler->getSmallPhotosForSet($value);
						$this->sesHandler->addPhotosFromFlickr($setName,$photoArray);
					}
				}
			}
		if(isset($_POST["logout"]))
		{
			$this->logOut();
		}
	}
	
	private function logOut()
	{
		$this->sesHandler->logout();
		header("location:login.php");
	}
}
?>